package compositeExpression;

import java.util.LinkedList;
import java.util.List;
import compositeExpression_Termp.DivTermp;
import compositeExpression_Termp.MulTermp;
import compositeExpression_Termp.RemTermp;
import visitor.Visitor;
import exceptions.IllegalContextException;

public class Term extends NumberExpression {
	
    private List<Expression> termp;

    public Term(Expression termp) {

        if (termp == null) {

            throw new NullPointerException();
        }

        this.termp = new LinkedList();
        this.termp.add(termp);
    }

	@Override
	public void toAssess(String p) throws IllegalContextException {
		 for (Expression tp : termp) {

	            tp.toAssess(p);
	        }
	}

	 public List<Expression> getState() {

	        return termp;
	    }

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

        for (Expression tr : termp) {

            if (tr instanceof DivTermp) {

                sb.append(" / ");
            } else if (tr instanceof MulTermp) {

                sb.append(" * ");
            } else if (tr instanceof RemTermp) {

                sb.append(" % ");
            }

            sb.append(tr);
        }
        return sb.toString();
    }
	

	@Override
    public void accept(Visitor v) {
        v.visit(this);
    }
	

	@Override
	public void add(Expression termp) {
		if (termp == null) {
            throw new NullPointerException();
        }

        this.termp.add(termp);
		
	}

}
